home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / postscri / lwheader.doc / LWHEADERFILE.DOC / LASERWRITER-HEADER.PS.1
Text File  |  1988-10-25  |  25KB  |  1,044 lines

  1. %!
  2. %         Macintosh LaserWriter header file.
  3. %
  4. % This is a file of PostScript definitions that can be affixed to the
  5. % front of the PostScript files generated by Macintosh applications in order
  6. % that they can be printed on a LaserWriter that has not been initialized
  7. % with the "LaserPrep" package. This situation will arise if you are
  8. % trying to share a LaserWriter between Macintosh users and non-Macintosh
  9. % users.
  10. %
  11. % Macintosh applications do not normally generate straight PostScript.
  12. % They generate a file in PostScript format, but the contents of the file
  13. % is a series of calls on functions that are not part of the PostScript
  14. % language. This file defines those functions.
  15. %
  16. % This is not the official Apple header file. It is neither endorsed nor
  17. % condemned by Apple. I suspect that it probably started out its life
  18. % as a bootleg copy of a version of the Apple header file. It has been
  19. % slightly modified by me and perhaps heavily modified by various other
  20. % people. I have substantially augmented the comments so that they explain
  21. % what I think the code is doing.
  22. %
  23. %    Brian Reid    Reid@SU-Glacier.ARPA
  24. %    Stanford    {decwrl,hplabs,bellcore}!glacier!reid
  25. %
  26. % WARNING: There is no guarantee that Apple will stick to this particular
  27. % set of definitions. This header file works with the application software
  28. % that came with my LaserWriter; I make no promises that it will work with
  29. % the software on anybody else's LaserWriter.
  30. % To convert this file back into a downloaded file instead of a header
  31. % file, uncomment all of the lines beginning with %-%
  32.  
  33. %-%0000000             % Server loop exit password
  34. %-%serverdict begin exitserver
  35. %-%  systemdict /statusdict known
  36. %-%  {statusdict begin 9 0 3 setsccinteractive /waittimeout 300 def end}
  37. %-% if
  38. /md 200 dict def        % define a working dictionary
  39. md begin            % start using it
  40. /av 13 def            % define apple version 
  41. /mtx matrix currentmatrix def    % save current transformation
  42. /s30 30 string def
  43. /s1 ( ) def
  44. /pys 1 def
  45. /pxs 1 def
  46. /pyt 760 def
  47. /pxt 29.52 def
  48. /por true def
  49. /xl {translate} def
  50. /fp {pnsh 0 ne pnsv 0 ne and} def
  51.  
  52. % Define QuickDraw operators as an array of procedures. 
  53. % They are {frame, paint, erase, invert, fill}
  54. % For some reason "invert" is a no-op.
  55.  
  56. /vrb [
  57. {fp
  58.  {gsave 1 setlinewidth pnsh pnsv scale stroke grestore}
  59.  if newpath} 
  60. {eofill}
  61. {eofill}
  62. {newpath}
  63. {eofill}
  64. {initclip eoclip newpath}
  65. {}
  66. {}
  67. {}
  68. {}
  69. ] def
  70.  
  71. % convenience function for backwards def
  72. /xdf {exch def} def
  73.  
  74. % get current halftone screen parameters 
  75. currentscreen
  76.     /spf xdf        % spot function
  77.     /rot xdf        % rotation
  78.     /freq xdf        % spatial frequency
  79.  
  80. % "apply" function to execute appropriate numbered operator from /vrb.
  81. /doop {vrb exch get exec} def
  82.  
  83. % compute page position from portrait/landscape flag, translation, scale,
  84. %    and resolution.
  85. %  call: P/L-flag xtransl ytransl scale*100 xbits/inch ybits/inch psu
  86. % typical call: F 580 760 100 72 72 psu for life-size screen-resolution
  87. % image.
  88. %
  89. /psu
  90.   {2 index .72 mul exch div /pys xdf    % pixel y scale
  91.   div .72 mul /pxs xdf            % pixel x scale
  92.  /pyt xdf                % pixel y translation
  93.  /pxt xdf                % pixel x translation
  94.  /por xdf                % portrait flag (T=portrait)
  95. } def
  96.  
  97. % argument is page y size; use this to determine legal, letter, or note
  98. % and to set up appropriate scale factors and translation/reflection
  99. % for portrait or landscape.
  100.  
  101. /txpose{
  102.     dup 1680 eq
  103.     userdict /note known
  104.       {{legal}{note}ifelse}
  105.       {pop}
  106.     ifelse
  107.     dup 1212 eq {54 32.4 xl} if
  108.     1321 eq {8.64 -.6 xl} if
  109.     pxs pys scale pxt pyt xl por not
  110.     {270 rotate} if
  111.     1 -1 scale
  112. } def
  113.  
  114. % Compute oblique shear value for font if flag true
  115. /obl {{0.212557 mul}{pop 0} ifelse} def
  116.  
  117. %  set font from dictionary: make a font, set it to current, leave on stack
  118. %  call: "found-font size oblique-flag dictionary sfd"
  119. /sfd {
  120.    [ps 0 ps 6 -1 roll obl ps neg 0 0] makefont
  121.    dup setfont
  122. } def
  123. /fnt {findfont sfd} def
  124.  
  125. % bit test-- "number mask-word bt" returns boolean and unchanged number
  126. % thus, "4095 512 bt" returns "true 4095" -- the argument is a mask
  127. % and not a bit number.
  128.  
  129. /bt {1 index and 0 ne exch} def
  130.  
  131. % load style array with unpacked true/false flags from style word
  132. % flags are Bold, Italic, Underline, Outline, Shadow (I don't know
  133. % what the 6th one is supposed to be).
  134. /sa 6 array def
  135. /fs {
  136.     1 bt     2 bt    4 bt    8 bt   16 bt
  137.    sa astore pop
  138. } def
  139.  
  140. /matrix1 matrix def
  141. /matrix2 matrix def
  142. /gf{
  143.   currentfont
  144. } def
  145.  
  146. % set translation center from 2 double-precision integers giving x,y
  147. /tc{
  148.    32768 div add         % compute y location
  149.    3 1 roll    
  150.    32768 div add         % compute x location
  151.    2t astore pop        % save 'em
  152. } def
  153.  
  154. /3a [0 0 0] def
  155. /2t 2 array def
  156.  
  157. % store transformation params: "justify flip rotation tp"
  158. % (left/center/right/full, none/yflip,xflip, degrees)
  159. /tp{
  160.    3a astore pop
  161. } def
  162. /ee {} def
  163.  
  164. % move PostScript current position to QuickDraw current position,
  165. % and get scaling and rotation right (this is in preparation for 
  166. % outputting text
  167. /tt {
  168.    gsave
  169.      currentpoint 2 copy
  170.      2t aload pop qa 2 copy xl
  171.      3a aload pop exch dup 0 eq
  172.      {pop}
  173.      {1 eq {-1 1}
  174.            {1 -1}ifelse scale}
  175.      ifelse
  176.      rotate
  177.      pop neg exch neg exch xl
  178.      moveto
  179. } def
  180.  
  181. /te {                % text-end: undo effects of prior "tt"
  182.    currentpoint currentfont
  183.    grestore setfont moveto    % but leave font and currentpoint set
  184. } def
  185.  
  186. /tb {                
  187.    /tg currentgray def
  188.    3 -1 roll 3 eq
  189.    {1 setgray} if
  190.    /ml 0 def /al 0 def
  191. } def
  192.  
  193. /am {
  194.    ml add /ml xdf
  195. } def
  196.  
  197. /aa {
  198.    [currentgray /setgray cvx] cvx
  199.    exch dup wi pop dup al add /al xdf exch
  200. } def
  201.  
  202. % scale by rational value (quotient) in x and y. Set "scaleflag" to
  203. % record that we have done this.
  204.  
  205. /th {
  206.    3 -1 roll div
  207.    3 1 roll exch div
  208. % not sure of "transform" in next line (BKR)
  209.    2 copy matrix1 transform scale
  210.    pop scale
  211.    /scaleflag true def
  212. } def
  213.  
  214. % undo a "th" scaling and return to default coordinate system
  215. /tu {
  216.    1 1 matrix1 itransform scale
  217.    /scaleflag false def
  218. } def
  219.  
  220. /ts {
  221.    1 1 matrix1 transform scale
  222.    /scaleflag true def
  223. } def
  224.  
  225. % record point size (of fonts)
  226. /fz{/ps xdf} def
  227.  
  228. % execute a procedure but leave it on the stack
  229. /fx{dup exec} def
  230.  
  231. /st{show pop pop} def
  232.  
  233. % text munger. This does the dirty work for the edit string procedure
  234. % (following) by iterating over a polymorphic array and doing the right
  235. % thing with what it finds there.
  236. /tm {
  237.       {dup type dup /integertype eq exch /realtype eq or
  238.          {dup ml mul}
  239.          {dup type /stringtype eq
  240.             {rs}
  241.             {dup type /dicttype eq
  242.                {setfont}
  243.                {dup type /arraytype eq
  244.                   {exec}
  245.                   {pop}
  246.           ifelse
  247.                } ifelse
  248.             } ifelse
  249.          } ifelse
  250.       } forall
  251.    } def
  252.  
  253. % edit string. Takes a font, a text mode, a justification mode, and an
  254. % array of text and font changes for that text, and does it.
  255. /es {
  256.    3 -1 roll dup sa 5 get dup type /nulltype eq
  257.    {pop4 pop}
  258.    {sa 1 get
  259.       {/ml ml .2 ps mul sub def} if
  260.       ne {fs}
  261.          {pop}
  262.       ifelse exch
  263.       dup 1 eq            % justification mode 1 is left-justify
  264.       {pop
  265.          al ml gt
  266.      {/tv {ll} /ml ml al dup 0 ne
  267.         {div}{pop} ifelse
  268.      def}
  269.      {/tv {st} /ml 1 def}
  270.      ifelse def tm
  271.       }
  272.       {dup 3 eq            % justification mode 3 is right-justify
  273.       {pop
  274.       al ml gt
  275.       {/tv {ll} /ml ml al dup 0 ne
  276.         {div}{pop} ifelse
  277.         def}
  278.       {ml al sub 0 rmoveto
  279.         /tv {st} /ml 1 def}
  280.       ifelse def
  281.          tm}
  282.       {2 eq            % justification mode 3 is centered
  283.       {al ml gt
  284.          { /tv {ll} /ml ml al dup
  285.        0 ne
  286.        {div}{pop}
  287.        ifelse def}
  288.      {ml al sub 2 div 0 rmoveto
  289.        /tv {st} /ml 1 def}
  290.        ifelse def
  291.          tm}
  292.       {                % otherwise it is just "justified"
  293.         /tv {ll} def
  294.         /ml ml al dup 0 ne
  295.       {div}{pop}
  296.       ifelse def
  297.          tm}
  298.        ifelse}
  299.      ifelse}
  300.    ifelse}
  301.    ifelse
  302.    tg setgray
  303. }def
  304.  
  305. /pop4 {pop pop pop pop} def
  306. % --------------------------------------------------------------------
  307. %              QuickDraw Procedures
  308. %
  309. % moveto. If a scale factor is in effect, then honor it.
  310. /gm {
  311.   scaleflag {matrix1 itransform} if
  312.   moveto
  313. } def
  314.  
  315. %local y move
  316. % call: "x y localy ly"
  317. /ly {
  318.    exch pop
  319.    currentpoint exch pop
  320.    sub 0 exch rmoveto
  321. } def
  322.  
  323. % print n copies of page  (ensures full speed for multiple copies)
  324. /page {
  325.    1 add /#copies xdf showpage
  326. } def
  327.  
  328. /sk {
  329.    systemdict /statusdict known
  330. } def
  331.  
  332. % set job name
  333. /jn {
  334.    sk {statusdict /jobname 3 -1 roll put}
  335.       {pop}
  336.    ifelse
  337. } def
  338.  
  339. % set pen size: h v pen
  340. /pen {
  341.    /pnsv xdf
  342.    /pnsh xdf
  343.    pnsh setlinewidth
  344. } def
  345.  
  346. % draw line
  347. % (uses current pen location, pen size and graylevel)
  348. % This emulates the ugly QuickDraw pen on the LaserWriter but
  349. % preserves the same endpoint and linewidth anomalies that some applications
  350. % rely on. (Bletch).
  351. /dlin {
  352.    currentpoint newpath moveto
  353.    lineto currentpoint stroke
  354.    grestore moveto
  355. } def
  356.  
  357. /lin {
  358.    currentpoint /pnlv xdf /pnlh xdf
  359.    gsave newpath /@y xdf /@x xdf fp
  360.    {pnlh @x lt
  361.       {pnlv @y ge
  362.          {pnlh pnlv moveto @x @y lineto
  363.       pnsh 0 rlineto
  364.           0 pnsv rlineto
  365.       pnlh pnsh add pnlv pnsv add lineto
  366.       pnsh neg 0 rlineto}
  367.          {pnlh pnlv moveto
  368.       pnsh 0 rlineto
  369.       @x pnsh add @y lineto
  370.       0 pnsv rlineto
  371.           pnsh neg 0 rlineto
  372.       pnlh pnlv pnsv add lineto}
  373.      ifelse}
  374.       {pnlv @y gt
  375.          {@x @y moveto pnsh 0 rlineto
  376.        pnlh pnsh add pnlv lineto
  377.       0 pnsv rlineto
  378.           pnsh neg 0 rlineto
  379.       @x @y pnsv add lineto}
  380.      {pnlh pnlv moveto pnsh 0 rlineto
  381.           0 pnsv rlineto
  382.       @x pnsh add @y pnsv add lineto
  383.       pnsh neg 0 rlineto
  384.           0 pnsv neg rlineto}
  385.      ifelse}
  386.       ifelse
  387.       closepath fill}
  388.    if @x @y grestore moveto
  389. } def
  390.  
  391. /dl {
  392.    gsave
  393.    0 setlinewidth 0 setgray
  394. } def
  395.  
  396. % Arc: top left bottom right startangle stopangle verb flag
  397. % flag true means to exclude the center of curvature in the arc
  398. /barc {
  399.    /@f xdf   /@op xdf   /@e xdf   /@s xdf
  400.    /@r xdf   /@b xdf    /@l xdf   /@t xdf
  401.    gsave
  402.    @r @l add 2 div @b @t add 2 div xl 0 0 moveto
  403.    @r @l sub @b @t sub mtx currentmatrix pop scale
  404.    @f {newpath} if
  405.    0 0 0.5 @s @e arc
  406.    mtx setmatrix @op doop
  407.    grestore
  408. } def
  409. /doarc {dup 0 eq barc} def
  410.  
  411. % oval:  top left bottom right verb
  412. /doval {0 exch 360 exch true barc} def
  413.  
  414. % rectangle:  top left bottom right verb
  415. /dorect {
  416.    /@op xdf currentpoint 6 2 roll 
  417.    newpath 4 copy
  418.    4 2 roll exch moveto
  419.    6 -1 roll lineto
  420.    lineto lineto closepath
  421.    @op doop moveto
  422. } def
  423.  
  424. /mup {dup pnsh 2 div le exch pnsv 2 div le or} def
  425.  
  426. % roundrect:  top left bottom right ovalwidth ovalheight operation
  427. % Warning: ovalwidth is assumed equal to ovalheight. 
  428. /dorrect {
  429.    /@op xdf     2. div /@h xdf     2. div /@w xdf
  430.    /@r xdf      /@b xdf            /@l xdf /@t xdf
  431.    @t @b eq @l @r eq @w mup or or
  432.    {@t @l @b @r @op dorect}
  433.    {@r @l sub 2. div dup @w lt
  434.       {/@w xdf}{pop}
  435.       ifelse
  436.       @b @t sub 2. div dup @w lt
  437.       {/@w xdf}{pop}
  438.       ifelse
  439.       @op 0 eq
  440.       {/@w @w pnsh 2 div sub def}
  441.       if            %this helps solve overlap gap for wide line widths
  442.       currentpoint
  443.       newpath
  444.       @r @l add 2. div @t moveto
  445.       @r @t @r @b @w arcto pop4
  446.       @r @b @l @b @w arcto pop4
  447.       @l @b @l @t @w arcto pop4
  448.       @l @t @r @t @w arcto pop4
  449.       closepath @op doop
  450.       moveto
  451.    }ifelse
  452. } def
  453.  
  454. % Polygon utility procedures
  455. /pr {
  456.    gsave newpath /pl
  457.       {moveto
  458.        /pl {lineto} def
  459.       }def
  460. } def
  461.  
  462. /pl {lineto} def
  463.  
  464. /ep {
  465.    dup 0 eq
  466.     {
  467.      {moveto}{lin}{}{}
  468.      pathforall %nothing but movetos and linetos should be called
  469.      pop grestore
  470.     }
  471.     {
  472.      doop grestore
  473.     }
  474.     ifelse
  475. } def
  476.  
  477. /bs 8 string def
  478. /bd {/bs xdf} def
  479.  
  480.  
  481.  
  482. % These following procedures are used in defining QuickDraw patterns.
  483. % (Pattern definition goes into halftone screen of PostScript)
  484.  
  485. % procedure to find black bits in QuickDraw pattern (pattern in hex string bs)
  486. /bit {bs exch get exch 7 sub bitshift 1 and} def
  487. /bix {1 add 4 mul cvi} def
  488. /pp{exch bix exch bix bit}def
  489. /grlevel {64. div setgray} def
  490.  
  491.  
  492. % procedure to set a pattern: ratio hexstring
  493. % ratio is the total number of white bits in the QuickDraw pattern represented in hexstring
  494.  
  495. /setpat {
  496.    /bs xdf
  497.    9.375 0 {pp} setscreen
  498.    grlevel
  499. } def
  500.  
  501. /setgry {
  502.    freq rot {spf} setscreen
  503.    grlevel
  504. } def
  505.  
  506. % standard copybits routine:
  507. % arguments: xscale yscale xloc yloc rowbytes xwidth ywidth fsmooth bitmode
  508. % This procedure is the basis for all QuickDraw bit operations.
  509. % xscale and yscale tell how much to scale the bit image in 72nds of an inch
  510. % xloc and yloc are the location of the top left corner of the bitmap
  511. % rowbytes is the total number of bytes in each scanline of hex data in the
  512. % image.
  513. %    Note that rowbytes must be even.
  514. % xwidth and ywidth are the actual number of bits in the x and y coordinates
  515. % of the image. fsmooth is a flag to tell whether or not to use bit
  516. % smoothing.  Bit smoothing is a
  517. % proprietary algorithm that provides smoothing of the data around a 5 by 5
  518. % local area of each data pixel.
  519. % bitmode can be any of the QuickDraw source transfer modes excluding srcXor
  520. % and notSrcXor.
  521. %    Note that this is the only QuickDraw procedure that can implement
  522. % more than the simple srcCopy transfer mode.
  523.  
  524. /x4 {2 bitshift} def
  525. /d4 {-2 bitshift} def
  526. /xf {.96 mul exch 2 sub .96 mul exch} def
  527. /dobits
  528. {
  529.    /bmode xdf
  530.    save 9 1 roll
  531. % 2 sub fixes dxsrc offset number required for bitsmoothing, but applies 
  532. % to both
  533.  
  534. %Bit Smooth mode
  535.    {
  536.    x4 /@dy xdf 2 sub x4 /@dx xdf /@idx xdf
  537.    .96 mul exch 3 index 2 sub @dx div 7.68 mul dup 6 1 roll sub exch xl 0 0 moveto xf
  538.    0 4 -1 roll 2 index 4 index 1.759 add 10 dorect clip newpath 0 0 moveto scale
  539.    bmode 0 eq bmode 4 eq or{1 setgray 1 @dy div 1 @dx div 1 1 2 dorect}if
  540.    bmode 3 eq bmode 7 eq or{1}{0}ifelse setgray
  541.    @idx 5 bitshift @dy bmode 0 eq bmode 1 eq bmode 3 eq or or [@dx 0 0 @dy 0 0]
  542.      {(%stdin)(r) file @dy d4 4 add @idx mul string readhexstring pop
  543.      dup length @idx x4 sub 4 bitshift string
  544.      dup 3 1 roll @dx 8 add d4 smooth} imagemask
  545.    }
  546. %Non Bit Smooth mode
  547.    {
  548.    /@dy xdf 2 sub /@dx xdf /@idx xdf
  549.    /@xs @idx string def
  550.    /@f (%stdin)(r) file def
  551.    /@p{@f @xs readhexstring pop}def
  552.    .96 mul xl 0 0 moveto xf scale
  553.    0 0 1 1 10 dorect clip newpath 0 0 moveto
  554.    bmode 0 eq bmode 4 eq or{1 setgray .25 @dy div .25 @dx div 1 1 2 dorect}if
  555.    bmode 3 eq bmode 7 eq or{1}{0}ifelse setgray
  556.    @p @p
  557.    @idx 3 bitshift @dy bmode 0 eq bmode 1 eq bmode 3 eq or or [@dx 0 0 @dy 0 0]
  558.    {@p} imagemask
  559.    @p @p pop4
  560.    }ifelse
  561. restore
  562. } def
  563.  
  564.  
  565. % Making Mac compatible Fonts
  566.  
  567.  
  568. /mfont 14 dict def
  569. /wd 14 dict def
  570. /mdef {mfont wcheck not{/mfont 14 dict def}if mfont begin xdf end} def
  571. /dc {transform round .5 sub exch round .5 sub exch itransform} def
  572.  
  573.  
  574. % Copy a font dictionary: fontdictionary
  575. % copies a font dictionary into tmp so it may be used to define a new font
  576.  
  577. % tmp must be set before cf is called
  578. /cf{{1 index /FID ne {tmp 3 1 roll put}{pop pop}ifelse}forall}def
  579.  
  580.  
  581. % Procedures used in defining a bit map font
  582.  
  583. /mv{tmp /Encoding macvec put}def
  584. /bf{
  585. mfont begin
  586. /FontType 3 def
  587. /FontMatrix [1 0 0 1 0 0] def
  588. /FontBBox [0 0 1 1] def
  589. /Encoding macvec def
  590. /BuildChar
  591.   {
  592.   wd begin
  593.     /cr xdf
  594.     /fd xdf
  595.     fd /low get cr get 2 get -1 ne
  596.     {
  597.     fd begin
  598.       low cr get aload pop
  599.       sd
  600.       low cr 1 add get 0 get
  601.       sh
  602.       sw
  603.     end
  604.     /sw xdf
  605.     /sh xdf
  606.     sw div /clocn xdf
  607.     dup 0 ne {0 exch sh div neg dc xl}{pop}ifelse
  608.     exch sw div /coff xdf
  609.     exch sw div /cloc xdf
  610.     /bitw clocn cloc sub def
  611.     sw sh div 1 scale
  612.     sw div 0 coff 0 bitw coff add 1 setcachedevice
  613.     coff cloc sub 0 dc xl
  614.     cloc .5 sw div add 0 dc newpath moveto
  615.     bitw 0 ne
  616.       {0 1 rlineto bitw .5 sw div sub 0 rlineto 0 -1 rlineto
  617.         closepath clip
  618.       sw sh false [sw 0 0 sh neg 0 sh]{fd /hm get}imagemask}if
  619.     } if
  620.   end
  621.   } def
  622. end
  623. mfont definefont pop
  624. } def
  625.  
  626.  
  627. % stringwidth procedure which does not allow a show to occur: (string)
  628.  
  629. /wi{save exch /show{pop}def
  630. stringwidth 3 -1 roll restore}def
  631.  
  632. /aps {0 get 124 eq}def
  633. /apn {s30 cvs aps} def
  634.  
  635.  
  636. %set style in a PostScript name: AppleFontName
  637. % e.g.
  638. % /|----name sos /|---Oname
  639. % /|----name sis /|-I--name
  640.  
  641. /xc{s30 cvs dup}def
  642. /xp{put cvn}def
  643. /scs{xc 3 67 put dup 0 95 xp}def
  644. /sos{xc 3 79 xp}def
  645. /sbs{xc 1 66 xp}def
  646. /sis{xc 2 73 xp}def
  647. /sob{xc 2 79 xp}def
  648. /sss{xc 4 83 xp}def
  649.  
  650. /dd{exch 1 index add 3 1 roll add exch} def
  651. /smc{moveto dup show} def
  652. /kwn{dup FontDirectory exch known{findfont exch pop}}def
  653. /fb{/ps ps 1 add def}def
  654. /mb
  655. {dup sbs kwn
  656.    {
  657.    exch{pop}{bbc}{} mm
  658.    }ifelse
  659. sfd
  660. }def
  661. /mo
  662. {dup sos kwn
  663.    {
  664.    exch{pop}{boc}{} mm
  665.    }ifelse
  666. sfd
  667. }def
  668. /ms
  669. {dup sss kwn
  670.    {
  671.    exch{pop}{bsc}{} mm
  672.    }ifelse
  673. sfd
  674. }def
  675.  
  676. /ao
  677. {dup sos kwn
  678.    {
  679.    exch dup ac pop
  680.    {scs findfont /df2 xdf}{aoc}{} mm
  681.    }ifelse
  682. sfd
  683. }def
  684.  
  685. /as
  686. {dup sss kwn
  687.    {
  688.    exch dup ac pop
  689.    {scs findfont /df2 xdf}{asc}{} mm
  690.    }ifelse
  691. sfd
  692. }def
  693.  
  694. /ac
  695.    {
  696.    dup scs kwn
  697.       {exch /ofd exch findfont def
  698.       /tmp ofd maxlength 1 add dict def
  699.       ofd cf mv
  700.       tmp /PaintType 1 put
  701.       tmp definefont}ifelse
  702.    }def
  703.  
  704. /mm{
  705. /mfont 10 dict def
  706. mfont begin
  707. /FontMatrix [1 0 0 1 0 0] def
  708. /FontType 3 def
  709. /Encoding macvec def
  710. /df 4 index findfont def
  711. /FontBBox [0 0 1 1] def
  712. /xda xdf
  713. /mbc xdf
  714. /BuildChar { wd begin
  715.   /cr xdf
  716.   /fd xdf
  717.   /cs s1 dup 0 cr put def
  718.   fd /mbc get exec
  719.   end
  720. } def
  721. exec
  722. end
  723. mfont definefont} def
  724. /bbc
  725. {
  726.   /da .03 def
  727.   fd /df get setfont
  728.   gsave
  729.     cs wi exch da add exchd
  730.   grestore
  731.   setcharwidth
  732.   cs 0 0 smc
  733.     da 0 smc
  734.     da da smc
  735.      0 da moveto show
  736. } def
  737.  
  738. /boc
  739. {
  740.   /da 1 ps div def
  741.   fd /df get setfont
  742.   gsave
  743.     cs wi
  744.     exch da add exch
  745.   grestore
  746.   setcharwidth
  747.   cs 0 0 smc
  748.     da 0 smc
  749.     da da smc
  750.      0 da smc
  751.   1 setgray
  752.      da 2. div dup moveto show
  753. } def
  754.  
  755. /bsc
  756. {
  757.   /da 1 ps div def
  758.   /ds .05 def %da dup .03 lt {pop .03}if def
  759.   /da2 da 2. div def
  760.   fd /df get setfont
  761.   gsave
  762.     cs wi
  763.     exch ds add da2 add exch
  764.   grestore
  765.   setcharwidth
  766.   cs ds da2 add .01 add 0 smc
  767.       0 ds da2 sub xl
  768.       0  0 smc
  769.      da  0 smc
  770.      da da smc
  771.       0 da smc
  772.   1 setgray
  773.       da 2. div dup moveto show
  774. } def
  775. /aoc
  776. {
  777.   fd /df get setfont
  778.   gsave
  779.     cs wi
  780.   grestore
  781.   setcharwidth
  782.   1 setgray
  783.   cs 0 0 smc
  784.   fd /df2 get setfont
  785.   0 setgray
  786.   0 0 moveto show
  787. }def
  788. /asc
  789. {
  790.   /da .05 def
  791.   fd /df get setfont
  792.   gsave
  793.     cs wi
  794.     exch da add exch
  795.   grestore
  796.   setcharwidth
  797.   cs da .01 add 0 smc
  798.       0 da xl
  799.   1 setgray
  800.       0 0 smc
  801.   0 setgray
  802.   fd /df2 get setfont
  803.       0 0 moveto show
  804. }def
  805.  
  806. /T true def
  807. /F false def
  808.  
  809.  
  810. % More Polygon stuff used in polygon comment
  811.  
  812. /6a 6 array def
  813. /2a 2 array def
  814. /5a 5 array def
  815. %subtract points, first from second (reverse order):  pt0 pt1 qs newpt
  816. /qs{3 -1 roll sub exch 3 -1 roll sub exch}def
  817. /qa{3 -1 roll add exch 3 -1 roll add exch}def
  818. %multiply point: pt factor qm newpt
  819. /qm{3 -1 roll 1 index mul 3 1 roll mul}def
  820. /qn{6a exch get mul}def
  821. /qA .166667 def /qB .833333 def /qC .5 def
  822. /qx{
  823.    6a astore pop
  824.    qA 0 qn qB 2 qn add  qA 1 qn qB 3 qn add
  825.    qB 2 qn qA 4 qn add  qB 3 qn qA 5 qn add
  826.    qC 2 qn qC 4 qn add  qC 3 qn qC 5 qn add
  827. }def
  828. /qp{6 copy 12 -2 roll pop pop}def
  829. /qc{qp qx curveto}def
  830. /qi{{4 copy 2a astore aload pop qa .5 qm newpath moveto}{2 copy 6 -2 roll 2 qm qs 4 2 roll}ifelse}def
  831. /qq{{qc 2a aload pop qx curveto}{4 copy qs qa qx curveto}ifelse}def
  832.  
  833. %start polygon comment
  834. /pt{gsave currentpoint newpath moveto}def
  835.  
  836. %fill smoothed poly
  837. /qf{gsave eofill grestore}def
  838. /tr{currentgray currentscreen bs 5a astore pop /fillflag 1 def}def
  839. /bc{/fillflag 0 def}def
  840.  
  841. %polyverb ec
  842. /ec{currentpoint 3 -1 roll
  843.    1 and 0 ne
  844.    {currentgray currentscreen bs 5a aload pop bd setscreen setgray 0 doop bd setscreen setgray}
  845.    {newpath}ifelse
  846.    moveto
  847. }def
  848.  
  849. /bp {
  850.    currentpoint newpath 2 copy moveto
  851.    currentgray currentscreen bs 5a astore pop
  852. } def
  853.  
  854. /eu{
  855.    fillflag 0 ne
  856.    {
  857.    gsave currentgray currentscreen bs
  858.    5a aload pop bd setscreen setgray
  859.    4 ep
  860.    bd setscreen setgray
  861.    }if
  862.    fp{0 ep}{grestore newpath}ifelse
  863. }def
  864.  
  865.  
  866. % Line Layout stuff used by string merging algorithm
  867.  
  868. % counts spaces in string:   (...) sm (...) n
  869. % returns string and number of spaces in string
  870.  
  871. /sm
  872. {
  873. dup 0 exch
  874. {32 eq{1 add}if}forall
  875. }
  876. def
  877.  
  878.  
  879. % layout a string to length specified by desiredlength:  printerlength desiredlength (...) ll
  880. % printerlength is length of string in printer space
  881.  
  882. /ll
  883. {
  884. 3 1 roll exch dup .0001 lt 1 index -.0001 gt and
  885. {pop pop pop}
  886. {sub dup 0 eq
  887.    {
  888.    pop show
  889.    }
  890.    {
  891.    1 index sm dup 0 eq 3 index 0 le or
  892.       {
  893.       pop length div
  894.       0 3 -1 roll ashow
  895.       }
  896.       {
  897. % This piece does 10 percent stretching in characters and 90 percent in spaces
  898.       10 mul exch length add div
  899.       dup 10 mul 0 32 4 -1 roll 0 6 -1 roll awidthshow
  900. % This piece does straight stretching in spaces only
  901. %      exch pop div
  902. %      0 32 4 -1 roll widthshow
  903.       }ifelse
  904.    }ifelse
  905. }ifelse
  906. }def
  907.  
  908.  
  909. %set font to symbol and show the string: (...) ss
  910.  
  911. /ss
  912. {  /pft currentfont def sa aload pop pop /|----2Symbol 4 1 roll
  913.    {pop{as}}
  914.    {{{ao}}{{fnt}}ifelse}ifelse
  915.    exch pop exec exch pop
  916. }def
  917. /pf{pft dup setfont}def
  918.  
  919.  
  920. % regular show does underline if ulf is true:
  921. % arguments: printerlength desiredlength string rs
  922.  
  923. /rs
  924. {
  925.    sa 2 get
  926.    {
  927.    gsave
  928.    1 index 0
  929.    currentfont
  930.    dup /FontInfo known
  931.       {
  932.       /FontInfo get
  933.       dup /UnderlinePosition known
  934.          {
  935.          dup /UnderlinePosition get 1000 div ps mul
  936.          }
  937.          {
  938.          ps 10 div neg  %15 makes line closer to text
  939.          }ifelse
  940.       exch
  941.       dup /UnderlineThickness known
  942.          {
  943.          /UnderlineThickness get 1000 div ps mul
  944.          }
  945.          {
  946.          pop
  947.          ps 15 div  %20 makes slightly narrower line
  948.          }ifelse
  949.       }
  950.       {
  951.       pop
  952.       ps 10 div neg   %15 makes line closer to text
  953.       ps 15 div       %20 makes slightly narrower line
  954.       }ifelse
  955.    setlinewidth
  956.    0 setgray
  957.    currentpoint 3 -1 roll sub moveto
  958.    sa 4 get{gsave currentlinewidth 2. div dup rmoveto currentpoint xl 2 copy rlineto
  959.    stroke grestore}if
  960.    sa 3 get sa 4 get or 3 1 roll 2 index{gsave 1 setgray 2 copy rlineto stroke grestore}if
  961.    rlineto{strokepath 0 setlinewidth}if stroke
  962.    grestore
  963.    }if
  964.    tv
  965. }
  966. def
  967.  
  968.  
  969. %  More Font building stuff, specifically the Apple Encoding Vector
  970.  
  971. % Font encoding vector for PostScript fonts to match Mac
  972. /macvec 256 array def
  973. macvec 0
  974. /Times-Roman findfont /Encoding get
  975. 0 128 getinterval putinterval macvec 39 /quotesingle put
  976.  /dotlessi /grave /circumflex /tilde /cedilla /registerserif 
  977.  /copyrightserif /trademarkserif
  978. macvec 0 8 getinterval astore pop
  979.  /Adieresis /Aring /Ccedilla /Eacute /Ntilde /Odieresis /Udieresis /aacute
  980.  /agrave /acircumflex /adieresis /atilde /aring /ccedilla /eacute /egrave
  981.  /ecircumflex /edieresis /iacute /igrave /icircumflex /idieresis /ntilde 
  982.  /oacute  /ograve /ocircumflex /odieresis /otilde /uacute /ugrave 
  983.  /ucircumflex /udieresis
  984.  /dagger /ring /cent /sterling /section /bullet /paragraph /germandbls
  985.  /registersans /copyrightsans /trademarksans /acute /dieresis /notequal 
  986.  /AE /Oslash
  987.  /infinity /plusminus /lessequal /greaterequal /yen /mu /partialdiff
  988.  /summation
  989.  /product /pi /integral /ordfeminine /ordmasculine /Omega /ae /oslash
  990.  /questiondown /exclamdown /logicalnot /radical /florin /approxequal /Delta 
  991.  /guillemotleft  /guillemotright /ellipsis /space /Agrave /Atilde /Otilde 
  992.  /OE /oe /endash /emdash /quotedblleft /quotedblright /quoteleft
  993.  /quoteright /divide /lozenge /ydieresis /Ydieresis /fraction /currency
  994.  /guilsinglleft /guilsinglright /fi /fl /daggerdbl /periodcentered
  995.  /quotesinglbase /quotedblbase /perthousand /Acircumflex /Ecircumflex /Aacute
  996.  /Edieresis /Egrave /Iacute /Icircumflex /Idieresis /Igrave /Oacute
  997.  /Ocircumflex /apple /Ograve /Uacute /Ucircumflex /Ugrave /dotlessi
  998.  /asciicircum /asciitilde /macron /breve /dotaccent /ring /cedilla
  999.  /hungarumlaut /ogonek /caron
  1000. macvec 128 128 getinterval astore pop
  1001.  
  1002. % now redefine all fonts using the MAC Encoding (except in Symbol) to make 
  1003. % them be Apple compatible.
  1004.  
  1005. FontDirectory
  1006. {exch dup s30 cvs /@s xdf @s aps
  1007.    {pop pop}
  1008.    {exch dup length dict /tmp xdf
  1009.       cf
  1010.       /Symbol ne {mv} if
  1011.       /@i false def /@o false def /@b false def
  1012.       mark @s (Italic) search {/@i true def} if (Oblique) search {/@o true def} if
  1013.       (Bold) search {/@b true def} if (Roman) search pop (-) search pop /@s xdf cleartomark
  1014.       @s cvn dup /Symbol eq{pop 50}{/Courier eq{51}{49}ifelse}ifelse
  1015.       s30 0 @s length 6 add getinterval dup 6 @s putinterval dup 0 (|-----) putinterval
  1016.       @b {dup 1 66 put} if @i @o or {dup 2 73 put} if % @o {dup 2 79 put} if
  1017.       dup 5 4 -1 roll put
  1018.       cvn tmp definefont pop
  1019.    }ifelse
  1020. }forall
  1021.  
  1022.  
  1023. %Make any other special fonts here, i.e. Seattle
  1024.  
  1025. /_--C-2Symbol /Symbol findfont /tmp 1 index maxlength 1 add dict def cf tmp /PaintType 1 put tmp definefont
  1026. /|----4Seattle /Helvetica findfont dup length 1 add dict /tmp xdf cf mv
  1027. /mxv [/zero /one /two /three /four /five /six /seven /eight /nine /comma /period /dollar /numbersign
  1028. /percent /plus /hyphen /E /parenleft /parenright /space] def
  1029. tmp /Metrics 21 dict dup begin mxv{600 def}forall end put
  1030. tmp begin /FontBBox FontBBox [0 0 0 0] astore def end
  1031. tmp definefont pop
  1032.  
  1033.  
  1034. % open document, open page and close page procedures
  1035. % close document doesn't do anything currently
  1036.  
  1037. % txpose takes the vertical page size as a parameter
  1038. /od{txpose 10 fz 0 fs F /|----3Courier fnt pop}def
  1039. /op{/scaleflag false def /pm save def}def
  1040. /cp{pm restore}def
  1041.  
  1042. end
  1043.